package com.str.PQ;
import java.io.*;

public class PriorityQueueTest {   

  public static void main(String args[]) throws IOException {
    BufferedReader stdin = new BufferedReader(
                           new InputStreamReader(System.in));
    PriorityQueue intPQ = new HeapPriorityQueue();
    Comparable value;
    
    while (true) {
      System.out.println("-------------------------");
      System.out.println("     1. Clear");      
      System.out.println("     2. Add");    
      System.out.println("     3. RemoveMin");
      System.out.println("     4. getMin");
      System.out.print("\tEnter your choice(Enter to quit): ");
      
      String inputLine = stdin.readLine();      
      if (inputLine.equals("")) {
        System.out.println("End of run.");
        System.exit(0);
      }    
      int choice = Integer.parseInt(inputLine);
      
      switch (choice) {
        case 1:
          System.out.println("Cleared.");
          intPQ.clear();
          break;
          
        case 2: 
          System.out.print("Enter an integer: ");
          inputLine = stdin.readLine();
          value = Integer.valueOf(inputLine);
          intPQ.add(value);
          break;
          
        case 3: 
          if (intPQ.isEmpty())
            System.out.println("Priority queue is empty.");
          else {
            value = intPQ.removeMin();
            System.out.println(value + " has been dequeued.");
          }
          break;
          
        case 4: 
          if (intPQ.isEmpty())
            System.out.println("Priority queue is empty.");
          else {
            value = intPQ.getMin();
            System.out.println("The minimal value is " + value);
          }
          break;
          
        default: 
          System.out.println("Invalid choice.");
          continue;
      }
      
      System.out.println(intPQ);
      System.out.println("Size = " + intPQ.size());
    }
  }
}
